<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('导入表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12 search-collapse">
      <div class="select-list">
        <ul>
          <li>
            <div class="col-sm-8">
              <select name="dbType" placeholder="数据源" class="form-control" th:with="item=${datasrcList}"
                      onchange="changeDatasrc(this)">
                <option value="">请选择数据源</option>
                <option th:each="datasrc : ${item}" th:text="${datasrc.connName}" th:value="${datasrc.id}"></option>
              </select>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="col-xs-12 select-table table-striped">
      <table id="grid-datasrc-table"></table>
    </div>
  </div>
</div>

<div th:include="include :: footer"></div>
<div th:include="include :: bizdk"></div>
<script th:inline="javascript">
    var prefix = ctx + "gen/table";

    $(function() {
        var options = {
            id: "grid-datasrc-table",
            modalName: "表格",
            sidePagination: "client",
            responseHandler: bizdk.listResponseHandler,
            columns: [{
                checkbox: true
            },
            {
                field : 'tableName',
                title : '表名'
            },
            {
                field : 'beanName',
                title : 'bean名称'
            },
            {
                field : 'tableComment',
                title : '表备注'
            }]
        };
        $.table.init(options);
    });

    function changeDatasrc(select) {
        var datasrcId = $(select).find("option:selected").val();
        if (datasrcId) {
            var params = {silent: false, url: prefix + "/table/list/" + datasrcId};
            $("#grid-datasrc-table").bootstrapTable('refresh', params);
        } else {
        }
    }


    /* 导入表结构-选择表结构-提交 */
    function submitHandler() {
        //$("#grid-datasrc-table").bootstrapTable('refresh', params);
        var rows = $.table.selectColumns("tableName");
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var datasrcId = $('select[name="dbType"]').find("option:selected").val();
        var data = {"tableNameList": rows.join()};
        $.operate.save(ctx + "gen/table/import/"+datasrcId, data);
    }

</script>
</body>
</html>